<?php

namespace App\Models ;

use Illuminate\Database\Eloquent\Model;

class SysTag extends Model
{

    protected $table = 'sys_tag';

    protected $primaryKey = 'tag_id';

    public $timestamps = false;

    public $incrementing = false;


    /**
     * 查询系统标签
     * @param $tag_type
     * @return mixed|null
     */
    public static function getCache( $tag_type )
    {

        if( empty($tag_type) ){
            return null;
        }

        //获取redis数据
        $tag_info = redisTransformation(app('redis')->get('GLOBAL_SYSTEM_TAG_' . $tag_type));
        if( !empty($tag_info) ){
            return $tag_info;
        }

        $tag_info = self::where(['tag_type'=>$tag_type])->first();
        if( $tag_info ){
            $tag_info = $tag_info->toArray();
            app('redis')->setex('GLOBAL_SYSTEM_TAG_' . $tag_type, 30*86400, redisTransformation($tag_info, 'set'));
            return $tag_info;
        } else {
            return null;
        }

    }

}
